﻿using Microsoft.EntityFrameworkCore;
using OnlineOpinionAnalysis.Server.Data;

namespace OnlineOpinionAnalysis.Server.Services
{
    public class BiliVideoService : IBiliVideoService
    {
        private readonly DataContext _dataContext;

        public BiliVideoService(DataContext dataContext)
        {
            _dataContext = dataContext;
        }

        // 获取视频信息
        public async Task<List<BiliVideo>> GetVideo(int number = 100)
        {
           var videos = await _dataContext.BiliVideos
                .Take (number)
                .OrderByDescending (video=>video.UpdateTime)
                .ToListAsync();
            return videos;
        }

        public async Task<List<BiliVideo>> GetVideoByTid(int tid, int number = 100)
        {
            List<BiliVideo> videos=new();
            videos= await _dataContext.BiliVideos.Where(video=>video.Tid== tid).Take(number).ToListAsync();
            return videos;
            //switch (tid)
            //{
            //    case 36:
            //        videos=await _dataContext.BiliKnowledgeVideos.Take(number).ToListAsync();
            //        break;
            //    case 1:
            //        videos = await _dataContext.BiliDougaVideos.Take(number).ToListAsync();
            //        break;
            //    case 13:
            //        videos = await _dataContext.BiliAnimeVideos.Take(number).ToListAsync();
            //        break;
            //    case 167:
            //        videos = await _dataContext.BiliGuoChuangVideos.Take(number).ToListAsync();
            //        break;
            //    case 4:
            //        videos = await _dataContext.BiliGameVideos.Take(number).ToListAsync();
            //        break;
            //    case 188:
            //        videos = await _dataContext.BiliTechVideos.Take(number).ToListAsync();
            //        break;
            //    case 160:
            //        videos = await _dataContext.BiliLifeVideos.Take(number).ToListAsync();
            //        break;
            //    case 119:
            //        videos = await _dataContext.BiliKichiKuVideos.Take(number).ToListAsync();
            //        break;
            //    default:
            //        break;
            //}
            //return videos;
        }

        public async Task<List<BiliVideo>> GetVideoByTime(DateTime StartTime, DateTime EndTime, int number = 100)
        {
            List<BiliVideo> videos =await _dataContext.BiliVideos.TakeWhile(video => video.UpdateTime > StartTime && video.UpdateTime < EndTime).ToListAsync();
            return videos;  
        }

        public async Task<int> GetVideoCount()
        {
            int count= await _dataContext.BiliVideos.CountAsync();
            return count;
        }
    }
}
